jQuery(document).ready(function() {
	///// SELECT WITH SEARCH /////
	jQuery(".chzn-select").chosen();
	
	/* initialize the calendar */
	jQuery('#calendar').fullCalendar({
		header : {
			left : '',
			center : 'title',
			right : 'today, prev, next'
		},
		
		monthNames : [ "一月", "二月", "三月", "四月",
				"五月", "六月", "七月", "八月", "九月",
				"十月", "十一月", "十二月" ],
		monthNamesShort : [ "一月", "二月", "三月",
				"四月", "五月", "六月", "七月", "八月",
				"九月", "十月", "十一月", "十二月" ],
		dayNames : [ "周日", "周一", "周二", "周三",
				"周四", "周五", "周六" ],
		dayNamesShort : [ "周日", "周一", "周二",
				"周三", "周四", "周五", "周六" ],
		today : [ "今天" ],
		firstDay : 1,
		allDaySlot : false,
		buttonText : {
			prev : '&laquo;',
			next : '&raquo;',
			prevYear : '&nbsp;&lt;&lt;&nbsp;',
			nextYear : '&nbsp;&gt;&gt;&nbsp;',
			today : '今天',
			month : '月',
			week : '周',
			day : '日'
		},
        eventClick: function(calEvent, jsEvent, view) {
        	//根据id设置
        	jQuery("#add_btn").hide();
			jQuery("#edit_btn").show();
			jQuery("#delete_btn").show();
			var id = calEvent.id;
			jQuery("#cardId").val(id);
			jQuery.ajax({
	        	type:"post",
	        	dataType:"json",
	        	url:"/timecard/info",
	        	data:{cardId:id},
	        	success:function(data) {
	        		var timecard = data.timecard;
	        		var empId = jQuery("#employeeSelect").val();
	    			jQuery("#empId").val(empId);
	        		var empName = jQuery("#empName").val();
	    			jQuery("#cardEmpName").val(empName);
	    			jQuery("#cardName").val(timecard.cardName);
	    			jQuery("#cardMoney").val(timecard.cardMoney);
	    			jQuery("#cardDate").val(timecard.cardDate);
	    			jQuery("#comment").val(timecard.cardComment);
	        	}
	        });
			
			jQuery("#timecard_dialog").dialog({
				width : 500,
				modal : true
			});
            
        }
	});
	
	jQuery("#calendar").fullCalendar('removeEvents');
	var empId = jQuery("#employee").val();
	jQuery.ajax({
    	type:"post",
    	dataType:"json",
    	url:"/timecard/events",
    	async:true,
    	data:{empId: empId},
    	success:function(data) {
    		if(data.flag) {
    			jQuery.each(data.events, function (index, term) {
                	jQuery("#calendar").fullCalendar('renderEvent', term, true);
                });
    		}
            
    	}
    });
	
	// /// SWITCHING LIST FROM 3 COLUMNS TO 2 COLUMN LIST /////
	function reposTitle() {
		if (jQuery(window).width() < 450) {
			if (!jQuery('.fc-header-title').is(':visible')) {
				if (jQuery('h3.calTitle').length == 0) {
					var m = jQuery('.fc-header-title h2')
							.text();
					jQuery(
							'<h3 class="calTitle">' + m
									+ '</h3>').insertBefore(
							'#calendar table.fc-header');
				}
			}
		} else {
			jQuery('h3.calTitle').remove();
		}
	}
	reposTitle();
	
	// /// ON RESIZE WINDOW /////
	jQuery(window).resize(function() {
		reposTitle();
	});
	
	
	
	jQuery("#date").datepicker({
		minDate: new Date()
	});
	
	
	
	jQuery('input:checkbox,input:radio').uniform();
});

